from selenium.webdriver.support.select import Select

from po_study.utils.Logger import Logger

logger = Logger('Base').getlog()


class Base():
    def __init__(self, driver):
        self.driver = driver

    def open(self, url):
        self.driver.get(url)
        logger.info(f'打开的网址为：{url}')
        self.driver.maximize_window()
        logger.info('最大化了浏览器窗口')

    def find_element(self, *locator):
        return self.driver.find_element(*locator)

    def input(self, locator, text):
        self.find_element(*locator).send_keys(text)
        logger.info(f'往{locator}中输入了{text}值')

    def click(self, locator):
        self.find_element(*locator).click()
        logger.info(f'点击了{locator}')

    def into_frame(self, frame_name):
        self.driver.switch_to.frame(frame_name)
        logger.info(f'进入了{frame_name}内帧')

    def out_frame(self):
        self.driver.switch_to.default_content()
        logger.info('出 帧')

    def select_by_text(self, locator, text):
        Select(self.find_element(*locator)).select_by_visible_text(text)
        logger.info(f'下拉框选择了{text}文本')

    def get_text(self, locator):
        text = self.find_element(*locator).text
        logger.info(f'得到了{locator}的{text}文本值')
        return text
